package com.ruoyi.system.WebController;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DownloadLog;
import com.ruoyi.system.service.IDownloadLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * downLogController
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/byWeb/downLog")
public class DownloadLogController extends BaseController
{
    @Autowired
    private IDownloadLogService downloadLogService;

    /**
     * 查询downLog列表
     */
    @PreAuthorize("@ss.hasPermi('system:downLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DownloadLog downloadLog)
    {
        startPage();
        List<DownloadLog> list = downloadLogService.selectDownloadLogList(downloadLog);
        return getDataTable(list);
    }

    /**
     * 导出downLog列表
     */
    @PreAuthorize("@ss.hasPermi('system:downLog:export')")
    @Log(title = "downLog", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DownloadLog downloadLog)
    {
        List<DownloadLog> list = downloadLogService.selectDownloadLogList(downloadLog);
        ExcelUtil<DownloadLog> util = new ExcelUtil<DownloadLog>(DownloadLog.class);
        util.exportExcel(response, list, "downLog数据");
    }

    /**
     * 获取downLog详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:downLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(downloadLogService.selectDownloadLogById(id));
    }

    /**
     * 新增downLog
     */
//    @PreAuthorize("@ss.hasPermi('system:downLog:add')")
//    @Log(title = "downLog", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DownloadLog downloadLog)
    {
        return toAjax(downloadLogService.insertDownloadLog(downloadLog));
    }

    /**
     * 修改downLog
     */
    @PreAuthorize("@ss.hasPermi('system:downLog:edit')")
    @Log(title = "downLog", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DownloadLog downloadLog)
    {
        return toAjax(downloadLogService.updateDownloadLog(downloadLog));
    }

    /**
     * 删除downLog
     */
    @PreAuthorize("@ss.hasPermi('system:downLog:remove')")
    @Log(title = "downLog", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(downloadLogService.deleteDownloadLogByIds(ids));
    }
}
